package com.hfzy.ihk.facade.websocket.linkcall.enums;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2016/11/23.
 *
 * @author wws
 */
public enum WebSocketMode {

    USE_LOCAL("使用本机webSocket", 1),
    USE_REMOTE("使用远程webSocket", 2);

    /** 描述 */
    private String label;

    /** 枚举值 */
    private int value;


    private WebSocketMode(String label, int value) {
        this.label = label;
        this.value = value;
    }

    public String getLabel() {
        return label;
    }

    public int getValue() {
        return value;
    }

    public static WebSocketMode getEnum(int value) {
        WebSocketMode resultEnum = null;
        WebSocketMode[] enumAry = WebSocketMode.values();
        for (int i = 0; i < enumAry.length; i++) {
            if (enumAry[i].getValue() == value) {
                resultEnum = enumAry[i];
                break;
            }
        }
        return resultEnum;
    }

    @SuppressWarnings({ "rawtypes", "unchecked" })
    public static List toList() {
        WebSocketMode[] ary = WebSocketMode.values();
        List list = new ArrayList();
        for (int i = 0; i < ary.length; i++) {
            Map<String, String> map = new HashMap<String, String>();
            map.put("value", String.valueOf(ary[i].getValue()));
            map.put("label", ary[i].getLabel());
            list.add(map);
        }
        return list;
    }

    public static Map<String, Map<String, Object>> toMap() {
        WebSocketMode[] ary = WebSocketMode.values();
        Map<String, Map<String, Object>> enumMap = new HashMap<String, Map<String, Object>>();
        for (int num = 0; num < ary.length; num++) {
            Map<String, Object> map = new HashMap<String, Object>();
            String key = String.valueOf(getEnum(ary[num].getValue()));
            map.put("value", String.valueOf(ary[num].getValue()));
            map.put("label", ary[num].getLabel());
            enumMap.put(key, map);
        }
        return enumMap;
    }
}
